package com.wehealth;




import java.util.Calendar;

import android.support.v4.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.config.ProjectConfig;
import com.umeng.analytics.MobclickAgent;
import com.wehealth.Plan_Week;
import com.wehealth.Plan_Day;
import com.wehealth.Dr_Select;
import com.wehealth.News_List;
import com.wehealth.Report;
import com.wehealth.Message;


public class Home extends Fragment {
	
   private MainActivity context;
   private static final int FREE_CONSULT = 1;
   private ImageView mLogo;
   private View home_layout;
 
	public Home() { 
		
	}
	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		return  inflater.inflate(R.layout.home, null);
	}
	
	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	
	}
	
	
	public void onActivityCreated(Bundle savedInstanceState){
			
			super.onActivityCreated(savedInstanceState);
			
			Log.i("fdafd","fdafdsaf");
			MainActivity activity = (MainActivity)getActivity();
			context = activity;
			
			mLogo= (ImageView)context.findViewById(R.id.logo);
			home_layout = (View)context.findViewById(R.id.home_layout);
			home_layout.setVisibility(View.INVISIBLE);


			
			if(context.getLogoAnimalState()){
				mLogo.setVisibility(View.VISIBLE);
				home_layout.setVisibility(View.INVISIBLE);
				context.setLogoAnimalState(false);
				myhandler.sendEmptyMessageDelayed(0, 500);
			}else{
				mLogo.setVisibility(View.INVISIBLE);
				home_layout.setVisibility(View.VISIBLE);
			}
			
			
			 Button bHome1 = (Button) activity.findViewById(R.id.b_home1);
				
			 bHome1.setOnClickListener(new View.OnClickListener()
				{
					public void onClick(View v)
					{
						
						Plan_Week planWeek = new Plan_Week();
						
						if (getActivity() instanceof MainActivity)
						{
							MainActivity activity = (MainActivity) getActivity();
							
							activity.switchContent(planWeek);
						}
						
						//Log.i("back home", " from: News_List"); 
					}
				});
			 
			 
			 
			 Button bHome2 = (Button) activity.findViewById(R.id.b_home2);
				
			 bHome2.setOnClickListener(new View.OnClickListener()
				{
					public void onClick(View v)
					{
						if(ProjectConfig.PROJECT_FOR_NORMAL){
						    Dr_Select drSelect = new Dr_Select();
						    context.switchContent(drSelect);
						}else{
						    ConsultationQestion cons = new ConsultationQestion(null,FREE_CONSULT);
						    context.switchContent(cons);
						}
					}
				});
			 
			 
			 
			 
			 
			 
			 Button bHome3 = (Button) activity.findViewById(R.id.b_home3);
				
			 bHome3.setOnClickListener(new View.OnClickListener()
				{
					public void onClick(View v)
					{
						Calendar calendar = Calendar.getInstance();
						int todayOfWeek =  calendar.get(Calendar.DAY_OF_WEEK);
						
						Log.i("todayOfWeek",Integer.toString(todayOfWeek));
						
						Plan_Day planDay = new Plan_Day(todayOfWeek-1);
						
						if (getActivity() instanceof MainActivity)
						{
							MainActivity activity = (MainActivity) getActivity();
							
							activity.switchContent(planDay);
						}
					}
				});
			 
			 
			 Button bHome4 = (Button) activity.findViewById(R.id.b_home4);
				
			 bHome4.setOnClickListener(new View.OnClickListener()
				{
					public void onClick(View v)
					{
						
						News_List newsList = new News_List();
						
						if (getActivity() instanceof MainActivity)
						{
							MainActivity activity = (MainActivity) getActivity();
							
							activity.switchContent(newsList);
						}
					}
				});
			 
			
			 Button bHome5 = (Button) activity.findViewById(R.id.b_home5);
				
			 bHome5.setOnClickListener(new View.OnClickListener()
				{
					public void onClick(View v)
					{
						
						Report report = new Report();
						
						if (getActivity() instanceof MainActivity)
						{
							MainActivity activity = (MainActivity) getActivity();
							
							activity.switchContent(report);
						}
					}
				});
			 
			 
			 Button bHome6 = (Button) activity.findViewById(R.id.b_home6);
				
			 bHome6.setOnClickListener(new View.OnClickListener()
				{
					public void onClick(View v)
					{
						
						Message message = new Message();
						
						if (getActivity() instanceof MainActivity)
						{
							MainActivity activity = (MainActivity) getActivity();
							
							activity.switchContent(message);
						}
					}
				});
			
			 

			 
	}
	
	

	//SIMMON_ADD begin
	    @Override
	    public void onPause() {
	        // TODO Auto-generated method stub
	        MobclickAgent.onPause(context);
	        super.onPause();
	        MobclickAgent.onPageEnd("HOME"); 
	      
	       
	    }


	    @Override
	    public void onResume() {
	        // TODO Auto-generated method stub
	        MobclickAgent.onResume(context);
	        super.onResume();
	        MobclickAgent.onPageStart("HOME"); 
	      
	    }
	    
	//SIMMON_ADD end
	    
	   
	   
	   private Handler myhandler = new Handler(){

		@Override
		public void handleMessage(android.os.Message msg) {
			// TODO Auto-generated method stub
			super.handleMessage(msg);
			
			AlphaAnimation animation2 = new AlphaAnimation(0, 1); 
			animation2.setDuration(1000);//设置动画持续时间 
			animation2.setFillAfter(true);

			AlphaAnimation animation = new AlphaAnimation(1, 0); 
			animation.setDuration(1000);//设置动画持续时间 
			animation.setFillAfter(true);
			mLogo.setAnimation(animation);
			home_layout.setAnimation(animation2);
			home_layout.setVisibility(View.VISIBLE);
			animation.start();
			animation2.start();

		}
		   
	   };

}